<template>
  <template v-if="user">
    <van-cell title="昵称" is-link to="/user/edit" :value="user.username" @click="toEdit('username','昵称',user.username)"/>
  <van-cell title="账号" :value="user.userAccount" />
  <van-cell title="头像" is-link to="/user/edit"/>
  <img style="height: 40px;" :src="user.avatarUrl"/>
  <van-cell title="性别" is-link to="/user/edit"  :value="user.gender" @click="toEdit( 'gender','性别',user.gender)"/>
  <van-cell title="电话" is-link to="/user/edit"  :value="user.phone" @click="toEdit( 'phone','电话',user.phone)"/>
  <van-cell title="邮箱" is-link to="/user/edit"  :value="user.email" @click="toEdit( 'email','邮箱',user.email)"/>
  <van-cell title="星球编号" is-link arrow-direction="down" :value="user.planetCode" />
  <van-cell title="注册时间" is-link arrow-direction="down" :value="user.createTime" />
  </template>
  <template v-else>
    <van-empty description="搜索为空" />
  </template>
</template>
  
<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { useRouter } from 'vue-router';
import { getCurrentUser } from '../services/user';

  // const user = {
  //   id: 1,
  //   username: '鱼皮' ,
  //   userAccount: 'yupi',
  //   avatarUrl: '',
  //   gender: '男',
  //   phone: '123456789',
  //   email: '1234567889@qq.com',
  //   planetCode: '1234',
  //   createTime: new Date(),
  // }

  const user = ref();

  onMounted(async () => {
    user.value = await getCurrentUser();
  })


const router = useRouter();
const toEdit = (editKey:string,editName:string,currentValue:string) => {
    router.push({
        path:'/user/edit',
        query: {
            editKey,
            currentValue,
            editName,
        }
    })
}

</script>
  
  <style>

</style>